package com.szbmyoubao.app.http.interceptor

import com.szbmyoubao.app.storage.AppStorage
import com.ellecity06.common.ktx.appVersionName
import com.ellecity06.cwhiskymall.BuildConfig
import okhttp3.Interceptor
import okhttp3.Response
import okio.IOException

class CommonHeaderInterceptor : Interceptor {
    @Throws(IOException::class)
    override fun intercept(chain: Interceptor.Chain): Response {
        val builder = chain.request().newBuilder()
        if (BuildConfig.SERVER_RELEASE) {
            if (AppStorage.Companion.token != null && AppStorage.Companion.token!!.isNotEmpty()) {
                builder.addHeader("Authori-zation", "${AppStorage.Companion.token}")
            }
        } else {
//            if (AppStorage.useLocalId){
                builder.addHeader("Authori-zation", "test:659")
//            }else {
//                builder.addHeader("Authori-zation", "${AppStorage.token}")
//            }


        }

        builder.addHeader("version", "v$appVersionName")
        builder.addHeader("platform", "Android")

        return chain.proceed(builder.build())
    }
}